using System;
using System.Collections.Generic;
using System.Text;
using Wrath.Xml;
using Wrath.RuleForge.Interfaces;
using System.ComponentModel;

namespace Wrath.RuleForge.Property
{
    public class CustomDieWrapper : IPropertyWrapper<Element>
    {
        private bool hasChanged;
        private Element element;

        // TODO: Model selection dropdown

        private Wrath.Xml.Attribute nameAttribute;
        private Element modelElement;
        private Element iconElement;
        private Element scriptElement;

        [Category("Custom Dice")]
        [Description("The name of the custom dice, shown in the custom dice menu.")]
        public string Name { get { if (nameAttribute != null) return nameAttribute.Value; return ""; } set { if (nameAttribute != null) nameAttribute.Value = value; } }

        [Category("Custom Dice")]
        [Description("The model on which the custom dice will be available. (d4, d6, d8, d10, d12, d20)")]
        public string Model { get { if (modelElement != null) return modelElement.Value; return ""; } set { if (modelElement != null) modelElement.Value = value; } }

        [Category("Custom Dice")]
        [DisplayName("Menu Icon")]
        [Description("The icon to use in the radial menu.")]
        public string Icon { get { if (iconElement != null) return iconElement.Value; return ""; } set { if (iconElement != null) iconElement.Value = value; } }

        [Category("Custom Dice")]
        [Description("The Lua script handling onValue and other events (using in-line Lua syntax).")]
        [Browsable(false)]
        public string Script { get { if (scriptElement != null) return scriptElement.Value; return ""; } set { if (scriptElement != null) scriptElement.Value = value; } }

        public CustomDieWrapper(Element element)
        {
            hasChanged = false;
            this.element = element;

            nameAttribute = element.FindAttribute("name");

            modelElement = element.FindFirstElement("model", false);
            iconElement = element.FindFirstElement("menuicon", false);
            scriptElement = element.FindFirstElement("script", false);

        }

        #region IPropertyWrapper<Element> Members

        [Browsable(false)]
        public bool HasChanged
        {
            get
            {
                return hasChanged;
            }
            set
            {
                hasChanged = value;
            }
        }

        [Browsable(false)]
        public Element Data
        {
            get { return element; }
        }

        #endregion
    }
}
